/*
 * @Author: nqx2007 fenglimima334@163.com
 * @Date: 2023-12-04 18:00:36
 * @LastEditors: nqx2007 fenglimima334@163.com
 * @LastEditTime: 2023-12-12 11:45:46
 * @FilePath: /operator-manager/src/pages/Access/index.tsx
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */

import { Access, useAccess } from '@umijs/max';

interface IAccessButton {
  accessKey: string;
  children: React.ReactNode;
}

export enum BtnAccessEnum {
  AUDIT = '审核',
  FORBIDDEN = '冻结',
  UNSEAL = '解封',
  ACCOUNT_ADD = '添加账号',
  ACCOUNT_EDIT = '编辑账号',
  ACCOUNT_FORBIDDEN = '禁用账号',
  ACCOUNT_OPEN = '启用账号',
  ROLE_ADD = '添加角色',
  ROLE_EDIT = '编辑角色',
  ROLE_DEL = '删除角色',
}

export const accessBtnMap = new Map([
  [BtnAccessEnum.AUDIT, 'business_manage_audit_btn'],
  [BtnAccessEnum.FORBIDDEN, 'business_manage_list_frozen'],
  [BtnAccessEnum.UNSEAL, 'business_manage_list_unseal'],
  [BtnAccessEnum.ACCOUNT_ADD, 'account_manage_add'],
  [BtnAccessEnum.ACCOUNT_EDIT, 'account_manage_edit'],
  [BtnAccessEnum.ACCOUNT_FORBIDDEN, 'account_manage_forbidden'],
  [BtnAccessEnum.ACCOUNT_OPEN, 'account_manage_open'],
  [BtnAccessEnum.ROLE_ADD, 'role_manage_add'],
  [BtnAccessEnum.ROLE_EDIT, 'role_manage_edit'],
  [BtnAccessEnum.ROLE_DEL, 'role_manage_del'],
]);
const AccessButton: React.FC<IAccessButton> = (props) => {
  const { accessKey, children } = props;
  const access = useAccess();

  return <Access accessible={access.hasBtnPerms(accessKey)}>{children}</Access>;
};

export default AccessButton;
